package com.guanyong.admin.controllers.page;

import com.google.gson.Gson;

import com.guanyong.admin.handle.UserHandle;
import com.guanyong.model.FuncModel;
import com.guanyong.model.RoleModel;
import com.guanyong.model.UserBaseModel;
import com.guanyong.services.FuncService;
import com.guanyong.services.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

/**
 * Created by Eric.Zhang on 2017/4/12.
 */
public class baseController {

    @Autowired
    UserHandle userHandle;
    @Autowired
    RoleService roleService;
    @Autowired
    FuncService funcService;

    UserBaseModel base_userEntity;

    @ModelAttribute
    public void   noaction(Model model,  HttpServletRequest request) {
        UserBaseModel userBaseModel=userHandle.getCurUser(request);
        if (userBaseModel!=null){
            model.addAttribute("userbaseinfo",userBaseModel);
            base_userEntity = userBaseModel;
            String url=request.getRequestURI();
            if(url.indexOf("/page/")>-1){
                Integer roleId=userBaseModel.getfRole();
                RoleModel roleModel=roleService.GetRoleById(roleId);
                List<FuncModel> funcModels=funcService.GetAllFuncModleByIdlist(roleModel.getfFuncs());
                Boolean isbool=false;
                for(FuncModel funcModel :funcModels){
                    if (funcModel.getfUrl()!=null && funcModel.getfUrl().equals(url)){
                        model.addAttribute("ptitle",funcModel.getfName());
                    }
                }


            }
            else{
                model.addAttribute("ptitle","首页-冠勇后台");
            }


        }
    }
}
